var status = 0;
var a = "#fEffect/CharacterEff/1003271/0/0#";  //红色心心
var a1 = "#fEffect/CharacterEff/1112904/0/0#";  //红色心心
var a2 = "#fEffect/CharacterEff/1082229/0/0#";  //红色心心
var z = "#fUI/UIWindow/Quest/icon5/1#";//"+z+"//美化
var z1 = "#fEffect/ItemEff/1112811/0/0#";//黄金音符
var z2 = "#fEffect/ItemEff/1004139/effect/jump/0#";
var z3 = "#fEffect/ItemEff/1048000/0/0#";//苹果红心
var ca = java.util.Calendar.getInstance();//
var year = ca.get(java.util.Calendar.YEAR); //获得年份
var month = ca.get(java.util.Calendar.MONTH) + 1; //获得月份
var day = ca.get(java.util.Calendar.DATE);//获取日
var hour = ca.get(java.util.Calendar.HOUR_OF_DAY); //获得小时
var minute = ca.get(java.util.Calendar.MINUTE);//获得分钟
var second = ca.get(java.util.Calendar.SECOND); //获得秒
var weekday = ca.get(java.util.Calendar.DAY_OF_WEEK); //获得星期
var time = new Date();
var sjr = time.getDay();
var tp = 0;

var minLevel = 180;
var maxLevel = 255;
var minPartySize = 1;
var maxPartySize = 6;
var maxenter = 5;
var PQLog = "情侣副本";

function start() {
    status = -1;
    action(1, 0, 0);
}

function action(mode, type, selection) {
    if (mode == -1) {
        cm.dispose();
    } else {
        if (mode == 0 && status == 0) {
            cm.dispose();
            return;
        }
        if (mode == 1) status++;
        else status--;
	if (cm.getPlayer().getClient().getChannel() == 1 || cm.getPlayer().getClient().getChannel() == 2 || cm.getPlayer().getClient().getChannel() == 3) {
        if (status == 0) {
        var selStr = "\t\t#r#e情侣" + z2 + "副本\r\n";
        selStr += z3 + z3 + z3 + z3 + z3 + z3 + z3 + z3 + z3 + z3 + z3 + z3 + z3 + z3 + z3;
        //selStr += a + a + a + a + a + a + a + a + a + a + a + a + a + a + a + a + a + a + a + a + a + "\r\n\r\n";
        //selStr += "#r#e　情深似海 情比金坚 生死相随 至死不渝 只为Ta#k#n\r\n";
        selStr += "#L0##r" + a1 + " 情侣档-挑战甜蜜小屋副本‖需伴侣在同一地图 " + a1 + "#l#k#n\r\n\r\n";
        selStr += z3 + z3 + z3 + z3 + z3 + z3 + z3 + z3 + z3 + z3 + z3 + z3 + z3 + z3 + z3;
        //selStr += a + a + a + a + a + a + a + a + a + a + a + a + a + a + a + a + a + a + a + a + a + "\r\n";
        cm.sendSimple(selStr);
		} else if (status == 1) {
            if (selection == 0) {
            if (cm.getParty() == null) { //判断组队
                cm.sendYesNo("你并没有组队，请创建组建一个队伍在来吧。");
            } else if (!cm.isLeader()) { // 判断组队队长
                cm.sendOk("请让你们的组队长和我对话。");
                        cm.dispose();
            } else if (!cm.allMembersHere()) {
                cm.sendOk("你的组队部分成员不在当前地图,请召集他们过来后在尝试。"); //判断组队成员是否在一张地图..
                        cm.dispose();
            } else if (!cm.isAllPartyMembersAllowedLevel(minLevel, maxLevel)) {
                cm.sendNext("组队成员等级 " + minLevel + " 以上 " + maxLevel + " 以下才可以入场。");
                        cm.dispose();
            } else if (!cm.isAllPartyMembersHaveItem(1112308, 1)) {
                cm.sendNext("你的队员#r#e \"" + cm.getNotHaveItemMemberName(1112308, 1) + "\" #k#n没有1个#i1112308##t1112308#,请确认!");
                        cm.dispose();
            } else if (!cm.isAllPartyMembersAllowedPQ(PQLog, maxenter)) {
                cm.sendNext("你的队员#r#e \"" + cm.getNotAllowedPQMemberName(PQLog, maxenter) + "\" #k#n次数已经达到上限了。");
                        cm.dispose();
			} else if (cm.getMap(889100001).getCharactersSize() > 0) {
				cm.sendOk("本次森林保卫战已经在进行中。请等待或者换线后尝试..");
					cm.dispose();
                    } else  {
		if (cm.getPQLog("情侣副本") <= 5){
		//if (cm.checkPartyEventCount("森林副本")){
                    var party = cm.getParty().getMembers();
                    var mapId = cm.getPlayer().getMapId();
                    var next = true;
                    var levelValid = 0;
                    var inMap = 0;
                    var it = party.iterator();
                    while (it.hasNext()) {
                        var cPlayer = it.next();
                        if ((cPlayer.getLevel() >= minLevel) && (cPlayer.getLevel() <= maxLevel)) {
                            levelValid += 1;
                        } else {
                            next = false;
                        }
                        if (cPlayer.getMapid() == mapId) {
                            inMap += 1;
                        }
                    }
                    if (party.size() < minPartySize || party.size() > maxPartySize || inMap < minPartySize) {
                        next = false;
                    }
                    if (next) {
                        var em = cm.getEventManager("LoveRsEvent");
                        if (em == null) {
                            cm.sendOk("此任务正在建设当中。");
                        } else {
                            var prop = em.getProperty("state");
                            if (prop.equals("0") || prop == null) {
                                em.startInstance(cm.getParty(), cm.getMap(), 198);
								cm.setPQLog("情侣副本");
								cm.worldSpouseMessage(0x22,"[爱情 - 甜蜜小屋] ：玩家 "+ cm.getChar().getName() +"带领他/她的伴侣 进入了爱情 - 甜蜜小屋。");
                                cm.dispose();
                                return;
                            } else {
                                cm.sendOk("怪任务里面已经有人了，请稍等！");
                            }
                        }
                        cm.dispose();
                    } else {
                        cm.sendOk("请确认你的组队员：\r\n\r\n#b1、组队员必须要" + minPartySize + "人以上，" + maxPartySize + "人以下。\r\n2、组队员等级必须要在" + minLevel + "级以上。\r\n\r\n（#r如果仍然错误, 重新下线,再登陆 或者请重新组队。#k#b）");
                        cm.dispose();
                    }
               // } else {
		//	cm.sendOk("请检查队伍中是否存在已完成次数#b队员#k。");
		//	cm.dispose();
		//	}
                } else {
			cm.sendOk("对不起，该帐号每天只能进入5次。\r\n");
			cm.dispose();
			}
		} //判断组队
            } else if (selection == 1) {
                cm.sendOk("请确认你的组队员：\r\n\r\n#b1、组队员必须要" + minPartySize + "人以上，" + maxPartySize + "人以下。\r\n2、组队员等级必须要在" + minLevel + "级以上。\r\n\r\n（#r如果仍然错误, 重新下线,再登陆 或者请重新组队。#k#b）");
                cm.dispose();
            }
        }
		 } else {
        		cm.dispose();
        		cm.sendOk("只有在1,2,3频道才可以参加任务。");
	}
    }
}